from app.models.song import Song
from google.appengine.ext import webapp
import os
from google.appengine.ext.webapp import template

class SongPage(webapp.RequestHandler):
    def get(self, bandname, songname):
        songs = Song.all()
        
        
        
        if ''.join([bandname, songname]).count("/") > 0:
            self.redirect("/error.html", permanent=True)
        properties = [self.request.body, self.request.body_file, self.request.remote_addr, 
                      self.request.url, self.request.path, self.request.query_string,
                      self.request.headers, self.request.cookies]
        template_values = {
            'songs': songs,
            'properties': properties,
            'args': [bandname, songname]
        }
        
        path = os.path.join(os.path.dirname(__file__), '../views/song.html')
        
        self.response.out.write(template.render(path, template_values))
        